package com.buaa.divinationmaster.core.database.entities;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

/**
 * 雷诺曼卡牌数据实体类
 * 包含36张雷诺曼卡牌的完整信息，每张卡牌有明确的象征意义
 */
@Entity(tableName = "lenormand_cards")
public class LenormandCard {
    
    @PrimaryKey
    public int id;                    // 1-36 (雷诺曼卡牌编号)
    
    @ColumnInfo(name = "name_zh")
    public String nameZh;             // 中文名称
    
    @ColumnInfo(name = "name_en") 
    public String nameEn;             // 英文名称
    
    @ColumnInfo(name = "number")
    public int number;                // 卡牌编号 (1-36)
    
    @ColumnInfo(name = "symbol")
    public String symbol;             // 符号/图案描述
    
    @ColumnInfo(name = "image_path")
    public String imagePath;          // 图片路径
    
    @ColumnInfo(name = "keywords")
    public String keywords;           // 核心关键词 (逗号分隔)
    
    @ColumnInfo(name = "meaning")
    public String meaning;            // 基本含义
    
    @ColumnInfo(name = "positive_meaning")
    public String positiveMeaning;    // 正面含义
    
    @ColumnInfo(name = "negative_meaning")
    public String negativeMeaning;    // 负面含义
    
    @ColumnInfo(name = "love_meaning")
    public String loveMeaning;        // 感情方面含义
    
    @ColumnInfo(name = "career_meaning")
    public String careerMeaning;      // 事业方面含义
    
    @ColumnInfo(name = "health_meaning")
    public String healthMeaning;      // 健康方面含义
    
    @ColumnInfo(name = "timing")
    public String timing;             // 时间含义
    
    @ColumnInfo(name = "combination_notes")
    public String combinationNotes;   // 组合解读要点
    
    // 默认构造函数
    public LenormandCard() {}
    
    // 带参构造函数 - Room忽略此构造函数
    @Ignore
    public LenormandCard(int id, String nameZh, String nameEn, int number, String symbol) {
        this.id = id;
        this.nameZh = nameZh;
        this.nameEn = nameEn;
        this.number = number;
        this.symbol = symbol;
    }
    
    // Getter和Setter方法
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    
    public String getNameZh() { return nameZh; }
    public void setNameZh(String nameZh) { this.nameZh = nameZh; }
    
    public String getNameEn() { return nameEn; }
    public void setNameEn(String nameEn) { this.nameEn = nameEn; }
    
    public int getNumber() { return number; }
    public void setNumber(int number) { this.number = number; }
    
    public String getSymbol() { return symbol; }
    public void setSymbol(String symbol) { this.symbol = symbol; }
    
    public String getImagePath() { return imagePath; }
    public void setImagePath(String imagePath) { this.imagePath = imagePath; }
    
    public String getKeywords() { return keywords; }
    public void setKeywords(String keywords) { this.keywords = keywords; }
    
    public String getMeaning() { return meaning; }
    public void setMeaning(String meaning) { this.meaning = meaning; }
    
    public String getPositiveMeaning() { return positiveMeaning; }
    public void setPositiveMeaning(String positiveMeaning) { this.positiveMeaning = positiveMeaning; }
    
    public String getNegativeMeaning() { return negativeMeaning; }
    public void setNegativeMeaning(String negativeMeaning) { this.negativeMeaning = negativeMeaning; }
    
    public String getLoveMeaning() { return loveMeaning; }
    public void setLoveMeaning(String loveMeaning) { this.loveMeaning = loveMeaning; }
    
    public String getCareerMeaning() { return careerMeaning; }
    public void setCareerMeaning(String careerMeaning) { this.careerMeaning = careerMeaning; }
    
    public String getHealthMeaning() { return healthMeaning; }
    public void setHealthMeaning(String healthMeaning) { this.healthMeaning = healthMeaning; }
    
    public String getTiming() { return timing; }
    public void setTiming(String timing) { this.timing = timing; }
    
    public String getCombinationNotes() { return combinationNotes; }
    public void setCombinationNotes(String combinationNotes) { this.combinationNotes = combinationNotes; }
    
    /**
     * 获取完整的卡牌标识
     */
    public String getFullIdentifier() {
        return number + ". " + nameZh + " (" + nameEn + ")";
    }
    
    /**
     * 获取主要关键词数组
     */
    public String[] getKeywordArray() {
        if (keywords == null || keywords.isEmpty()) {
            return new String[0];
        }
        return keywords.split(",");
    }
    
    /**
     * 根据占卜主题获取对应含义
     */
    public String getMeaningByTheme(String theme) {
        if (theme == null) return meaning;
        
        switch (theme.toLowerCase()) {
            case "love":
            case "感情":
                return loveMeaning != null ? loveMeaning : meaning;
            case "career":
            case "事业":
                return careerMeaning != null ? careerMeaning : meaning;
            case "health":
            case "健康":
                return healthMeaning != null ? healthMeaning : meaning;
            case "positive":
            case "正面":
                return positiveMeaning != null ? positiveMeaning : meaning;
            case "negative":
            case "负面":
                return negativeMeaning != null ? negativeMeaning : meaning;
            default:
                return meaning;
        }
    }
    
    /**
     * 检查是否包含特定关键词
     */
    public boolean hasKeyword(String keyword) {
        if (keywords == null || keyword == null) return false;
        return keywords.toLowerCase().contains(keyword.toLowerCase());
    }
    
    /**
     * 判断卡牌整体倾向 (基于正负面含义)
     */
    public String getOverallTendency() {
        if (positiveMeaning != null && !positiveMeaning.isEmpty()) {
            if (negativeMeaning != null && !negativeMeaning.isEmpty()) {
                return "中性"; // 既有正面又有负面含义
            }
            return "正面";
        } else if (negativeMeaning != null && !negativeMeaning.isEmpty()) {
            return "负面";
        }
        return "中性";
    }
    
    @Override
    public String toString() {
        return "LenormandCard{" +
                "id=" + id +
                ", nameZh='" + nameZh + '\'' +
                ", nameEn='" + nameEn + '\'' +
                ", number=" + number +
                ", symbol='" + symbol + '\'' +
                '}';
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        LenormandCard that = (LenormandCard) obj;
        return id == that.id;
    }
    
    @Override
    public int hashCode() {
        return Integer.hashCode(id);
    }
}
